package com.itrip.biz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itrip.beans.pojo.AreaDic;
import com.itrip.beans.pojo.Hotel;
import com.itrip.beans.pojo.LabelDic;
import com.itrip.beans.vo.HotelVideoDescVO;
import com.itrip.beans.vo.ItripAreaDicVO;
import com.itrip.biz.service.AreaDicService;
import com.itrip.biz.service.HotelService;
import com.itrip.biz.service.LabelDicService;
import com.itrip.utils.dto.Dto;
import com.itrip.utils.util.EmptyUtils;
import com.itrip.utils.vo.DtoUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(value = "API", basePath = "酒店信息Controller")
@RestController
@RequestMapping(value = "/biz/api/hotel")
public class HotelController {
    @Autowired
    private AreaDicService areaDicService;
    @Autowired
    private LabelDicService labelDicService;
    @Autowired
    private HotelService hotelService;

    //查询热门城市的接口s
    @GetMapping("/queryhotcity/{type}")
    public Dto<AreaDic> queryHotcity(@PathVariable Integer type) {
        QueryWrapper<AreaDic> wrapper = new QueryWrapper<AreaDic>();
        wrapper.eq("is_hot", 1);
        wrapper.eq("is_china", type);
        List<AreaDic> itripAreaDics = areaDicService.list(wrapper);
        return DtoUtil.returnDataSuccess(itripAreaDics);
    }


    //查询酒店特色列表
    @GetMapping("/queryhotelfeature")
    public Dto<LabelDic> queryHotelFeature() {
        QueryWrapper<LabelDic> wrapper = new QueryWrapper<LabelDic>();
        wrapper.eq("parent_id", 16);
        List<LabelDic> labelDicList = labelDicService.list(wrapper);
        return DtoUtil.returnDataSuccess(labelDicList);
    }

    @GetMapping("/querytradearea/{cityId}")
    public Dto<ItripAreaDicVO> queryTradeArea(@PathVariable Long cityId) {
        List<AreaDic> areaDicList = null;
        List<ItripAreaDicVO> areaDicVOList = null;
        if (EmptyUtils.isNotEmpty(cityId)) {
            Map param = new HashMap();
            param.put("isTradingArea", 1);
            param.put("parent", cityId);
            areaDicVOList = areaDicService.getItripAreaDicListByMap(param);
            if (EmptyUtils.isNotEmpty(areaDicList)) {
                areaDicVOList = new ArrayList();
                for (AreaDic dic : areaDicList) {
                    ItripAreaDicVO vo = new ItripAreaDicVO();
                    BeanUtils.copyProperties(dic, vo);
                    areaDicVOList.add(vo);
                }
            }
        }else {
            DtoUtil.returnFail("cityId不能为空");
        }
        return DtoUtil.returnDataSuccess(areaDicVOList);
    }

    //根据酒店id查询酒店特色、商圈、酒店名称
    @GetMapping("/getvideodesc/{hotelId}")
    public Dto getVideoDescByHotelId(@PathVariable String hotelId){
        HotelVideoDescVO hotelVideoDescVO = new HotelVideoDescVO();
        List<AreaDic> itripAreaDicList = new ArrayList<>();
        itripAreaDicList = areaDicService.getHotelAreaByHotelId(Long.valueOf(hotelId));
        List<String> tempList1 = new ArrayList<>();
        for (AreaDic itripAreaDic:itripAreaDicList) {
            tempList1.add(itripAreaDic.getName());
        }
        hotelVideoDescVO.setTradingAreaNameList(tempList1);

        List<LabelDic> itripLabelDicList = new ArrayList<>();
        itripLabelDicList = labelDicService.getHotelFeatureByHotelId(Long.valueOf(hotelId));
        List<String> tempList2 = new ArrayList<>();
        for (LabelDic itripLabelDic:itripLabelDicList) {
            tempList2.add(itripLabelDic.getName());
        }
        hotelVideoDescVO.setHotelFeatureList(tempList2);

        hotelVideoDescVO.setHotelName(hotelService.getById(Long.valueOf(hotelId)).getHotelName());
        return DtoUtil.returnSuccess("获取酒店视频文字描述成功",hotelVideoDescVO);
    }

    //根据酒店 ID 获取 酒店介绍以及特色
    @GetMapping("/queryhoteldetails/{hotelId}")
    public Dto<LabelDic> getHotelDetailsById(@PathVariable String hotelId){
        List<LabelDic> labelDicList=hotelService.queryHotelDetails(hotelId);
        return DtoUtil.returnDataSuccess(labelDicList);
    }

    //更具酒店ID 查询 酒店设施
    @GetMapping("/queryhotelfacilities/{hotelId}")
    public Dto getHotelFacilities(@PathVariable String hotelId){
        Hotel hotel=hotelService.getById(Long.valueOf(hotelId));
        return DtoUtil.returnDataSuccess(hotel.getFacilities());
    }

    //根据酒店ID 查询酒店政策
    @GetMapping("/queryhotelpolicy/{hotelId}")
    public Dto getHotelPolicy(@PathVariable String hotelId){
        Hotel hotel=hotelService.getById(Long.valueOf(hotelId));
        return DtoUtil.returnDataSuccess(hotel.getHotelPolicy());
    }
}
